{include file="common/header" /}
<link href="__STATIC__/js/codemirror/codemirror.css" rel="stylesheet">
<link href="__STATIC__/js/codemirror/ambiance.css" rel="stylesheet">
<style>
    body {
        background-color: #ffffff;
    }
    .img-item {
        position: relative;
        width: 96px;
        height: 96px;
        border-radius: 6px;
        margin-bottom: 10px;
        margin-right: 10px;
    }
    .img-item img {
        border-radius: 6px;
        width: 100%;
        height: 100%;
    }
    .img-item i {
        font-size: 20px;
        position: absolute;
        top: -10px;
        right: -10px;
    }

</style>
<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>操作-编辑</legend>
</fieldset>
<div class="layui-form layuimini-form">
  	<form class="layui-form layui-form-pane" action="{:url('template/edit')}">  
	<input type="hidden" name="fname" value={:input('param.fname')}>
  
    <div class="layui-form-item">
	    <label class="layui-form-label">文件名称</label>
	    <div class="layui-input-block" style="width:500px;">
	      <input type="text" class="layui-input field-file" name="file" value="{$file}" autocomplete="off" placeholder="请输入文件名称" >
	    </div>
	</div>
	
	<div class="layui-form-item">
	    <label class="layui-form-label">css替换</label>
	    <div class="layui-input-inline" >
	      <input type="text" class="layui-input field-css" name="css" value="" autocomplete="off" placeholder="css/" >
	    </div>
	    <label class="layui-form-label">替换成</label>
	    <div class="layui-input-inline" >
	      <input type="text" class="layui-input field-upcss" name="upcss" value="" autocomplete="off" placeholder="__INDEXCSS__/" >
	    </div>
	    <div class="layui-form-mid layui-text-em">__INDEXCSS__/</div>
	</div>
	
	<div class="layui-form-item">
	    <label class="layui-form-label">js替换</label>
	    <div class="layui-input-inline" >
	      <input type="text" class="layui-input field-js" name="js" value="" autocomplete="off" placeholder="js/" >
	    </div>
	    <label class="layui-form-label">替换成</label>
	    <div class="layui-input-inline" >
	      <input type="text" class="layui-input field-upjs" name="upjs" value="" autocomplete="off" placeholder="__INDEXJS__/" >
	    </div>
	    <div class="layui-form-mid layui-text-em">__INDEXJS__/</div>
	</div>
	
	<div class="layui-form-item">
	    <label class="layui-form-label">image替换</label>
	    <div class="layui-input-inline" >
	      <input type="text" class="layui-input field-image" name="image" value="" autocomplete="off" placeholder="images/" >
	    </div>
	    <label class="layui-form-label">替换成</label>
	    <div class="layui-input-inline" >
	      <input type="text" class="layui-input field-upimage" name="upimage" value="" autocomplete="off" placeholder="__INDEXIMG__/" >
	    </div>
	    <div class="layui-form-mid layui-text-em">__INDEXIMG__/</div>
	</div>
	
	
	 <div class="layui-form-item layui-form-text">
	    <label class="layui-form-label" style="width:600px;">内容</label>
	    <div class="layui-input-block" >
	      
	      	<textarea id="content" name="content" >{$all_file | raw}</textarea>
			
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <div class="layui-input-block">
	      <button class="layui-btn" lay-submit lay-filter="submitForm">立即提交</button>
	      <a href="{:url('index',array('fname'=>input('param.fname')))}" class="layui-btn layui-btn-primary">返回</a>
	    </div>
	  </div>
    </form>
</div>
 
<script src="__STATIC__/js/codemirror/codemirror.js"></script>
<script src="__STATIC__/js/codemirror/mode/javascript/javascript.js"></script>

<script>
    $(document).ready(function(){
    	var editor_one=CodeMirror.fromTextArea(
    		document.getElementById("content"),{
    			lineNumbers:true,matchBrackets:true,styleActiveLine:true,theme:"ambiance"
    		});
    	editor_one.setSize('height','400px');
    	
    });
</script>

<script>

    layui.use(['form','iconPickerFa'], function () {
        var form = layui.form,
            iconPickerFa = layui.iconPickerFa,
            layer = layui.layer,
            $ = layui.$;


        //监听提交
        form.on('submit(submitForm)', function (data) {
            var index = layer.load(1, {
                shade: [0.3,'#000'] //0.1透明度的白色背景
            });
            var data = data.field;
            $.ajax({
                url:"{:url('template/edit')}",
                data:data,
                type:'post',
                dataType:'json',
                success:function(res){
                    // console.log(res)
                    // return false
                    if(res.errcode != 1){
                        layer.msg(res.message,{icon: 2,time: 2000},function(){
                            layer.close(index);
                        })
                    }else{
                        layer.msg(res.message,{icon: 1,time: 1000},function () {
                            //window.location.href = "{:url('policy/list')}";
                            location.reload();
                        })
                    }
                    layer.close(index);
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('网络失败，请刷新页面后重试!',{icon: 2,time: 2000})
                }
            });

            return false;
        });

    });
</script>
</body>
</html>